<%@ page language="java" import="java.util.*,mymail.*,javax.mail.*,javax.mail.internet.MimeMessage,java.text.DateFormat,javax.mail.internet.MimeUtility" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String p;
if(request.getParameter("page")==null)
	p = "1";
else
{
	p = request.getParameter("page");
	if(!request.getParameter("page").matches("^\\d+$")||Integer.parseInt(p)<1)
		p = "1";
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>OUR | Mailbox</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

</head>

<body >
	<% 
	  // String host = request.getParameter("host");     
     //  String username = request.getParameter("username");
     //  String password = request.getParameter("password");
       
      // username=username.substring(0, username.indexOf("@"));
       String  host=null;
       
      		String username=null;
    	   String password=null;
      if(request.getAttribute("host")!=null)
       {
    	   host =request.getAttribute("host").toString();
           username=request.getAttribute("username").toString();
    	   password=request.getAttribute("password").toString();
       }else if(session.getAttribute("username")!=null)
       {
    	   host=(String)session.getAttribute("host");
    	   username=(String)session.getAttribute("username");
    	   password=(String)session.getAttribute("password");
       }
       session.setAttribute("username", username);
       session.setAttribute("password", password);
       session.setAttribute("host", host);
       System.out.println("username_mailbox:"+username+"host:"+host);
       String from = "";
       String from0 = "";
       String subject = ""; 
       String sendDate=""; 
       Folder folder = POP3.getFolder(host,username,password);
       session.setAttribute("folder",folder);
       Message[] messages=null;
       if(folder==null)
       {
    	   messages=null;
    	   
       }
       else
           messages = folder.getMessages();
       DoReceive rec=null;
      // String ifAttch;
   %>
   
     <div >

        <div   class="gray-bg">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top white-bg" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <span class="navbar-minimalize minimalize-styl-2 btn btn-primary" style=" margin-left:38px" >our邮箱 </span>
         </div>	
		
            <ul class="nav navbar-top-links navbar-right">
              <li> <span class="m-r-sm text-muted welcome-message" style="font-size: 28px;font-family:jokerman;color: #8FB586"><strong>hello,welcome to our emailbox!</strong>&nbsp;&nbsp;&nbsp;<%=username%>@arman.com</span> </li>
              <li>
                    <a href="index.jsp">
                        <i></i> 退出	
                    </a>
                </li>
            </ul>

        </nav>
        </div>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-lg-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-content mailbox-content">
                        <div class="file-manager">
                          
                            
                         
                            <ul class="folder-list m-b-md" style="padding: 0">
                                <li><a href="mailbox.jsp?username=<%=username+"@arman.com"%>&password=<%=password%>"  style="font-size:17px;"> <i > </i>收件箱</a></li>
                                  <li><a href="mailbox.html"  style="font-size: 17px; "> <i></i>发件箱</a></li>
                                <li><a href="mailbox.html" style="font-size: 17px; "> <i ></i>星标邮箱</a></li>
                                <li><a href="mailbox.html" style="font-size: 17px; "> <i></i>草稿箱</a></li>
                                <li><a href="mailbox.html" style="font-size: 17px; "> <i></i>垃圾箱</a></li>
                            <div class="space-25"></div>
							  <li><a  href="mail_send.jsp" style="font-size: 20px; font-family:jokerman"><i></i><strong>Write Letter</strong></a></li>
                          </ul>
                            <div class="clearfix"></div>
                            <div class="space-25"></div>
                             <img src="img/p4.jpg" width="270" height="230" alt=""/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-9 animated fadeInRight">
            <div class="mail-box-header">

                 
                <h2>
                    收件箱 
                </h2>
                <div class="mail-tools tooltip-demo m-t-md">
                    
                    <button class="btn btn-primary btn-sm" >标位已读</button>
                    <button class="btn btn-primary btn-sm" >记为星标 </button>
                    <button class="btn btn-white btn-sm" >删除 </button>
                     <button class="btn btn-primary btn-sm" ><i class="fa fa-refresh"></i> 刷新</button>

                </div>
            </div>
                <div class="mail-box">
                  <table class="table table-hover table-mail">
                <tbody>
                <%
               // out.println("<table class='table table-hover select-table'><thead> <tr>");
                if(messages!=null)
                {
                	for(int i=0;i<messages.length;i++){
               
                	//try{
           				rec=new DoReceive((MimeMessage)messages[i]);
                		from0 = rec.getFrom();
                		from=from0;
                		subject = messages[i].getSubject();
                		sendDate = rec.getSendDate();
                		//ifAttch=Boolean.toString(rec.isContainAttch(messages[i]));                	    
                  	   // messages = folder.getMessages();                                  
          				/*	 out.println("<tr data-id='fname="+ messages[i].getFrom()+ "'>");
          		           /*  if(session.getAttribute("priv0")!=null){
          		                 out.println("<td><span class='glyphicon'></span></td>");
          		             }else{
          		                 out.println("<td></td>");
          		             }*/
          		             //out.println("<td>"+ i +"</td>");
          		/*             out.println("<td>" +rec.getFrom() + "</td>");
          		             out.println("<td>" + rec.getSubject() + "</td>");
          		             /* out.println("<td>" + messages[i].getType() + "</td>"); */
          		  /*          out.println("<td>" + rec.getSendDate()+ "</td>");	           
          		             if(rec.isNew())
          		               	out.println("<td></td></tr>");
          		             else
          		               	out.println("<td>read </td></tr>");
                   		    
*/
             //    }
           		   
                //    catch(Exception e){}
                  
               // out.println("</tbody></table>");	
             
 				%>
 					<tr class="read">             
                    <td class="mail-ontact">来自：<a href="mail_detail.jsp?msgnum=<%=i+1%>&username=<%=username%>&password=<%=password%>"><%=from %></a></td>
                    <td class="mail-subject">主题：<a href="mail_detail.jsp?msgnum=<%=i+1%>&username=<%=username%>&password=<%=password%>"><%=subject %></a></td>
            <!--    <c:set var="ifAttch" value=""/>
                    <c:choose>
		      		<c:when test="${ifAttch=='true'}">
		       			<td class=""><i class="fa fa-paperclip"></i></td>
		      		</c:when>
		      		<c:otherwise>
		      			<td class=""></td>
		      		</c:otherwise>
		      		</c:choose>
                   -->    
                   <td class="text-right mail-date"><%=sendDate %></td>
                 </tr>
             <%
                }	
                }
       			
             %>   
               </tbody>
                <div class="btn-group pull-right">
                        <button class="btn btn-primary btn-sm"><i >上一页</i></button>
                        <button class="btn btn-primary btn-sm"><i >下一页</i></button>

                    </div>
                   
                </table>
              </div>
            </div>
        </div>
        </div>
       

        </div>
        </div>
    <!-- Mainly scripts -->
    <script src="js/jquery-2.1.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="js/inspinia.js"></script>
    <script src="js/plugins/pace/pace.min.js"></script>

    <!-- iCheck -->
    <script src="js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function(){
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
	 
</body>
<div  >
            
            <div style=" text-align:center">
                <strong></strong> our电子邮箱@软件1401班
            </div>
        </div>
</html>
